package jwj8508.mvc.actions;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jwj8508.mvc.dao.BoardDAO;
import jwj8508.mvc.model.BoardVO;

public class UpdateBoardAction implements ActionHandler {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
				
		String viewPage = "f|/WEB-INF/jsp/tiles/mvc.jsp";
		String method = req.getMethod();
		
		if (method.equalsIgnoreCase("get")) {
			req.setAttribute("action", "../board/update.jsp");
			String bdno = req.getParameter("bdno");
			req.setAttribute("b", BoardDAO.viewBoard(bdno));
		} else if (method.equalsIgnoreCase("post")) {
			req.setAttribute("action", "../board/list.jsp");
			viewPage = "r|listBoard.mvc";
			req.setCharacterEncoding("UTF-8");
			BoardVO b = new BoardVO();
			b.setBdno(req.getParameter("bdno"));
			b.setTitle(req.getParameter("title"));
			b.setUid(req.getParameter("uid"));
			b.setContents(req.getParameter("contents"));
			BoardDAO.updateBoard(b);
		}
		return viewPage;
	}

}
